﻿// Copyright (c) 2012 - 2020 Jared Zheng <jaredz at outlook dot com>
// Buddha Framework is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Create : 2012-12-01 version 0.1 Jared Zheng <jaredz at outlook dot com>
// Update : 2018-12-05 version 3.1.5 Jared Zheng <jaredz at outlook dot com>

#ifndef __MAIN_FRAME_H__
#define __MAIN_FRAME_H__

#pragma once

#include "resource.h"
#include "ServerLoader.h"

///////////////////////////////////////////////////////////////////////////////////////////////////////////
/// 服务加载器主界面
class CMainFrame : public CXFrameWnd, public CEventHandler
{
public:
    enum FRAME_CONST
    {
        FRAMEC_WIDTH       = 800,
        FRAMEC_HEIGHT      = 600,
        FRAMEC_TABGRAP     = 2,
        FRAMEC_TABHEIGHT   = 28,

        FRAMEC_STATUS      = 4,
        FRAMEC_TIMER       = 101,
        FRAMEC_TIMER_TIME  = 500,
        FRAMEC_TIME_SECOND = 1000,
        FRAMEC_TIME_DAY    = 24,
        FRAMEC_TIME_HOUR   = 3600,
        FRAMEC_TIME_MINUTE = 60,
    };

    static CPCXStr ANM_STATUS;
public:
    CMainFrame(void);
    virtual ~CMainFrame(void);
    // CEventHandler
    virtual UInt OnHandle(Int nEvent, uintptr_t utData, ULLong ullParam) OVERRIDE;
    virtual UInt OnHandle(Int nEvent, CEventBase& pParam, ULLong ullParam) OVERRIDE;
    virtual UInt OnHandle(Int nEvent, CStream& Stream, ULLong ullParam) OVERRIDE;
    virtual UInt OnHandle(Int nEvent, UInt uCount) OVERRIDE;
protected:
    virtual LRESULT OnCreate(LPCREATESTRUCT lpCS) OVERRIDE;
    virtual void    OnDestroy(void) OVERRIDE;
    virtual void    FrameLayout(void) OVERRIDE;
    virtual LRESULT OnNotify(Int nID, LPNMHDR pHead, BOOL& bHandled) OVERRIDE;

    LRESULT OnTimer(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnGetMinMaxInfo(WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnCommand(WORD wCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
    LRESULT OnXNotify(WPARAM wParam, LPARAM lParam, BOOL& bHandled);

    XBEGIN_INLINE_MSG_MAP( CMainFrame )
    // {{ --
        XMSG_HANDLER(WM_TIMER, OnTimer)
        XMSG_HANDLER(WM_GETMINMAXINFO, OnGetMinMaxInfo)
        XCOMMAND_RANGE_HANDLER(IDC_START, IDC_EXIT, OnCommand)
        XMSG_XUIM_NOTIFY()
        XMSG_WM_CREATE()
        XMSG_WM_DESTROY()
    // --}}
    XEND_CHAIN_MSG_MAP( CXFrameWnd )
private:
    void OnStart(void);
    void OnPause(void);
    void OnStop(bool bRepaint = true);
    void OnUpdate(void);

    bool LoadServerDlgs(void);
    void LayoutServerDlgs(void);
    void UpdateServerDlgs(bool bStart = true);
    void UnloadServerDlgs(void);

    bool CreateServerDlg(Int nIndex);
    bool InsertServerDlg(Int nLoad, Int nIndex, CXUITraits::CREATE_PARAM& cpm);
private:
    Int           m_nIndex;
    Int           m_nTimes;
    Int           m_nTabSel;
    UInt          m_uStart;
    UInt          m_uLoad;
    CCommonDlg*   m_pServerDlg[PAKT_MAX];
    CSyncEvent    m_hBusyLoad;
    CSyncEvent    m_hOverLoad;
    CXToolBar     m_CmdBar;
    CXStatusBar   m_StatusBar;
    CXTab         m_Servers;
    XChar         m_szStatus[LMT_KEY];
};

#endif // __MAIN_FRAME_H__
